package com.jlg.managers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jlg.beans.groupon.CategoryBean;
import com.julewa.db.DB;
import com.julewa.db.Identifier;

@Component
@SuppressWarnings("unchecked")
public class CategoryManager
{
    private @Autowired
    DB db;
    private @Autowired
    Identifier idsrv;

    public long save(CategoryBean om)
    {
        long id = idsrv.generate("category");
        om.setId(id);
        boolean bool = db.insert("category.insert", om);
        if (bool)
        {
            return id;
        } else
        {
            return -1;
        }
    }

    public List<CategoryBean> getAll()
    {
        return db.getList("category.all", null);
    }

    public CategoryBean findByName(String categoryName)
    {
        Object obj = db.getObject("category.findByName", categoryName);
        if (obj != null)
        {
            return (CategoryBean) obj;
        }
        return null;
    }

}
